package toman.jdbc;

import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.ResultSetHandler;
import toman.*;

import javax.persistence.TemporalType;
import java.sql.SQLException;
import java.util.*;

/**
 * User: zslajchrt
 * Date: 2.5.11
 * Time: 16:36
 */
public abstract class ResultSetQuery<T> extends ListTOQuery<T> {

    private final String sql;

    private final QueryRunner run;
    private final ResultSetHandler h;
    private final Object[] parameters;

    public ResultSetQuery(String sql, Class<T> toCls, TOMan toMan, QueryRunner run, ResultSetHandler resultSetHandler,
                          List<Object> parameters) {
        super(toMan, toCls);
        this.sql = sql;
        this.run = run;
        this.h = resultSetHandler;
        this.parameters = parameters.toArray(new Object[parameters.size()]);
    }

    @Override
    protected List<Object> createRawDataList() throws SQLException {
        return run.<List<Object>>query(sql, h, parameters);
    }
}

